package com.aw.guiguzi.module.setting

import android.widget.RelativeLayout
import android.widget.TextView
import com.aw.baselib.base.AwBaseBindingActivity
import com.aw.baselib.util.AwRecyclerViewUtil
import com.aw.guiguzi.R
import com.aw.guiguzi.databinding.ActivitySettingHelpBinding
import com.aw.guiguzi.module.setting.adapter.HelpImgAdapter
import com.aw.guiguzi.util.AppUserUtil.isAdmin
import com.aw.guiguzi.util.DataUtil.matcherSearchTextDiffArea
import com.aw.guiguzi.util.StrUtil.matcherSearchText

class HelpActivity : AwBaseBindingActivity<ActivitySettingHelpBinding>() {
    private var mAdapter: HelpImgAdapter? = null
    private val mImgList: MutableList<Int> = ArrayList()

    override fun getViewBinding(): ActivitySettingHelpBinding {
        return ActivitySettingHelpBinding.inflate(mActivity.layoutInflater)
    }

    override fun initView() {
        super.initView()
        for (i in 0 until binding.llExplain.childCount) {
            val childView = binding.llExplain.getChildAt(i)
            if (childView is RelativeLayout) {
                for (j in 0 until childView.childCount) {
                    val subChildView = childView.getChildAt(j)
                    if (subChildView is TextView) {
                        val content = subChildView.text.toString()
                        subChildView.text = matcherSearchText(
                            R.color.purple_200,
                            content,
                            content.split("：".toRegex()).dropLastWhile { it.isEmpty() }
                                .toTypedArray()[0] + "："
                        )
                    }
                }
            } else if (childView is TextView) {
                val content = childView.text.toString()
                childView.text = matcherSearchText(
                    R.color.purple_200,
                    content,
                    content.split("：".toRegex()).dropLastWhile { it.isEmpty() }
                        .toTypedArray()[0] + "："
                )
            } else {
            }
        }
        showView(binding.llBettingSingleHint, isAdmin)
    }

    override fun initData() {
        super.initData()
        setToolbar("使用教程", null)
        mImgList.add(R.drawable.img_template1)
        mImgList.add(R.drawable.img_template2)
        mImgList.add(R.drawable.img_template3)
        mImgList.add(R.drawable.img_template5)
        mImgList.add(R.drawable.img_template4)
        mAdapter = HelpImgAdapter()
        AwRecyclerViewUtil.setRecyclerViewLinearlayout(mActivity, binding.rcvData, mAdapter, false)
        mAdapter!!.addAllData(mImgList)
        showView(findViewById(R.id.ll_calIntroduce), isAdmin)
        val tv_helCal = findViewById<TextView>(R.id.tv_helCal)
        tv_helCal.text = matcherSearchTextDiffArea(
            getString(R.string.hint_help_cal),
            resources.getColor(com.aw.baselib.R.color.red),
            arrayOf("走势（一）", "走势（二）", "走势（三）"),
            true,
            resources.getColor(com.aw.baselib.R.color.blue),
            arrayOf(
                "走势1",
                "走势2",
                "走势3",
                "走势4",
                "走势5",
                "走势6",
                "走势7",
                "走势8"
            ),
            true
        )
    }

    override fun initListener() {
        super.initListener()
    }
}